package entities_testCase;

import junit.framework.TestCase;
import entities.Course;
import entities.Section;
import entities.AcdcProgram;

public class CourseTest extends TestCase {
	private String CourseCode1;
	private String CourseCode2;
	Course c1;
	Course c2;
	Section section0;
	Section section1;
	Section section2;
	String[] program1;
	String[] program2;
	AcdcProgram[] prgm;

	public void setUp() {
		program1 = new String[1];
		program2 = new String[2];
		CourseCode1 = "cs3343";
		CourseCode2 = "cs3103";
		program1[0] = "BSCCS2";
		program2[0] = "BSCCS2";
		program2[1] = "BSCCS3";

		prgm = new AcdcProgram[2];
		prgm[0] = new AcdcProgram(program2[0]);
		prgm[1] = new AcdcProgram(program2[1]);

		c1 = new Course(CourseCode1, program1);
		c2 = new Course(CourseCode2, program2);

		section0 = new Section("sectionId1", 60, 2, "AC8");
		section1 = new Section("sectionId2", 60, 2, "AC8");
		section2 = new Section("sectionId3", 60, 2, "AC8");
	}

	public void tearDown() {
		Course.clear();
		Section.clear();
		AcdcProgram.clear();
	}

	public void test_insertTwice() {
		new Course(CourseCode1, program1);
		assertEquals(2, Course.getAllCourses().length);
	}

	public void test_nullProgramList() {
		Course noProgram = new Course("noProgram", null);
		assertEquals(0, noProgram.getPrograms().length);
	}

	public void test_getCourseCode() {
		assertEquals(CourseCode1, c1.getCourseCode());
	}

	public void test_addLecture_getAllLecture() {
		// loop 0 time
		String[] le = null;
		le = c1.getAllLecture();
		assertEquals(0, le.length);

		// loop 1 time
		c1.addLecture("sectionId1");
		le = c1.getAllLecture();
		assertEquals(1, le.length);

		// loop many times
		c1.addLecture("sectionId2");
		le = c1.getAllLecture();
		assertEquals(2, le.length);
	}

	public void test_addTutorial_getAllTutorial() {
		// loop 0 time
		String[] tut = null;
		tut = c1.getAllTutorial();
		assertEquals(0, tut.length);

		// loop 1 time
		c1.addTutorial("sectionId1");
		tut = c1.getAllTutorial();
		assertEquals(1, tut.length);

		// loop many times
		c1.addTutorial("sectionId2");
		tut = c1.getAllTutorial();
		assertEquals(2, tut.length);
	}

	public void test_getPrograms() {
		String[] program1 = c1.getPrograms();
		String[] program2 = c2.getPrograms();
		assertEquals("BSCCS2", program1[0]);
		assertEquals("BSCCS2", program2[0]);
		assertEquals("BSCCS3", program2[1]);
	}

	public void test_getAllCourses() {
		Course.clear();
		String[] arrCourses = null;

		// loop 0 time
		arrCourses = Course.getAllCourses();
		assertEquals(0, arrCourses.length);

		// loop 1 time
		new Course(CourseCode1, program1);
		arrCourses = Course.getAllCourses();
		assertEquals(1, arrCourses.length);

		// loop many times
		c2 = new Course(CourseCode2, program2);
		arrCourses = Course.getAllCourses();
		assertEquals(2, arrCourses.length);
	}
}
